#include <stdafx.h>
#include "Shaders.h"

int Shaders::Init()
{
	vertexShader = esLoadShader(GL_VERTEX_SHADER, fileVS);

	if ( vertexShader == 0 )
		return -1;

	fragmentShader = esLoadShader(GL_FRAGMENT_SHADER, fileFS);

	if ( fragmentShader == 0 )
	{
		glDeleteShader( vertexShader );
		return -2;
	}

	program = esLoadProgram(vertexShader, fragmentShader);

	//finding location of uniforms / attributes
	positionAttribute = glGetAttribLocation(program, "a_posL");
	a_Nomal = glGetAttribLocation(program, "a_Nomal");
	texcoordAttribute = glGetAttribLocation(program, "a_uv");
	textureAttribute = glGetUniformLocation(program, "u_texture");
	cameraAttribute=glGetUniformLocation(program,"campos");
	spotLight=glGetUniformLocation(program,"spotLight");
	AmbientComponent=glGetUniformLocation(program,"AmbientComponent");
	LightDiffuseColor=glGetUniformLocation(program,"LightDiffuseColor");
	LightSpecularColor=glGetUniformLocation(program,"LightSpecularColor");

	a_tangentL=glGetUniformLocation(program,"a_tangentL");
	a_bitangentL=glGetUniformLocation(program,"a_bitangentL");

	mvpMatrixUniform=glGetUniformLocation(program,"u_mvpMatrix");
	Heigh_Map=glGetUniformLocation(program,"Heigh_Map");
	Blend_Map=glGetUniformLocation(program,"Blend_Map");
	Dirt_Map=glGetUniformLocation(program,"Dirt_Map");
	Grass_Map=glGetUniformLocation(program,"Grass_Map");
	Rock_Map=glGetUniformLocation(program,"Rock_Map");
	u_texture0=glGetUniformLocation(program,"u_texture0");
	u_texture1=glGetUniformLocation(program,"u_texture1");
	u_texture2=glGetUniformLocation(program,"u_texture2");
	ma_ViewAttribute=glGetUniformLocation(program,"ma_View");
	u_modelMatrix=glGetUniformLocation(program,"u_modelMatrix");
	u_modelTranpose	=glGetUniformLocation(program,"u_modelTranpose");
	offset=glGetUniformLocation(program,"offset");
	return 0;
}

Shaders::~Shaders()
{
	glDeleteProgram(program);
	glDeleteShader(vertexShader);
	glDeleteShader(fragmentShader);
}

void Shaders::CleanUp(){
	delete fileVS;
	delete fileFS;
}